;;; cc.cfg.el --- Summary
;;; Commentary:
;;; configuration for C languages
;;; Code:
(require 'package.cfg)

(if
    (executable-find "global")
    (progn
      (package-install-if-absent 'helm-gtags)

      (use-package helm-gtags
        :init
        (add-hook 'dired-mode-hook 'helm-gtags-mode)
        (add-hook 'eshell-mode-hook 'helm-gtags-mode)
        (add-hook 'c-mode-hook 'helm-gtags-mode)
        (add-hook 'c++-mode-hook 'helm-gtags-mode)
        (add-hook 'asm-mode-hook 'helm-gtags-mode)
        :config
        (setq
         helm-gtags-ignore-case t
         helm-gtags-auto-update t
         helm-gtags-use-input-at-cursor t
         helm-gtags-pulse-at-cursor t
         helm-gtags-prefix-key "\C-cg"
         helm-gtags-suggested-key-mapping t)
        (define-key helm-gtags-mode-map (kbd "C-c g a") 'helm-gtags-tags-in-this-function)
        (define-key helm-gtags-mode-map (kbd "C-j") 'helm-gtags-select)
        (define-key helm-gtags-mode-map (kbd "M-.") 'helm-gtags-dwim)
        (define-key helm-gtags-mode-map (kbd "M-,") 'helm-gtags-pop-stack)
        (define-key helm-gtags-mode-map (kbd "C-c <") 'helm-gtags-previous-history)
        (define-key helm-gtags-mode-map (kbd "C-c >") 'helm-gtags-next-history)
        :diminish helm-gtags-mode))
  (message "%s: GNU GLOBAL not found in exec-path. helm-gtags will not be used." 'cc.cfg))

(use-package cc-mode
  :init
  (setq c-default-style "stroustrup")
  (add-hook 'c-mode-common-hook 'hs-minor-mode)
  :config
  (use-package smartparens)
  (sp-with-modes '(c++-mode)
    (sp-local-pair "{" nil :post-handlers '(("||\n[i]" "RET"))))
  (sp-local-pair 'c++-mode "/*" "*/" :post-handlers '((" | " "SPC")
                                                      ("* ||\n[i]" "RET")))
  :mode ("\\.h\\'" . c++-mode)
  :bind (("C-c f" . ff-find-other-file)))

(provide 'cc.cfg)
;;; cc.cfg.el ends here
